#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long Ull;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;
string s;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
		cin>>s;
		
		double ans=0;
		
		for(int i=0;i<s.size();i++)
		{
			int a[30]={0};
			a[s[i]-'a']++;
			double ans1=0;
		
		for(int j=i+1;j<s.size();j++)
		{
			ans1+=a[s[j]-'a'];
			a[s[j]-'a']++;
			ans=max(ans1/(j-i+1),ans);
		}
	    }
	    printf("%.6lf",ans);
	}

	return 0;
}

